package st.business.tepth.business.history;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.bean.HistoryResultBean;

/**
 * @author zhangyu
 * @date 2019/3/2
 */
public class HistoryResultAdapter extends BaseQuickAdapter<HistoryResultBean, BaseViewHolder> {
    public HistoryResultAdapter(int layoutResId, @Nullable List<HistoryResultBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HistoryResultBean item) {
        helper.setText(R.id.tv_bus_code, item.getBusNumber());
        helper.setText(R.id.tv_work_type, item.getWorkType());
        helper.setText(R.id.tv_arrive_time, item.getArrive());
        helper.setText(R.id.tv_out_time, item.getLeave());
        helper.setText(R.id.tv_work_begin_time, item.getBegin());
        helper.setText(R.id.tv_work_end_time, item.getEnd());
        helper.setText(R.id.tv_driver, item.getDriverName() +
                "(" + item.getDriverCode() + ")");
        helper.setText(R.id.tv_report_content, convertRepairs(item.getRepairs()));
        helper.setText(R.id.tv_state, item.getState());
        helper.addOnClickListener(R.id.tv_report_content_detail);
        helper.addOnClickListener(R.id.tv_operation);
    }

    private String convertRepairs(List<HistoryResultBean.RepairsBean> repairs) {
        StringBuilder string = new StringBuilder();
        if (repairs != null) {
            for (HistoryResultBean.RepairsBean repairsBean : repairs) {
                string.append(repairsBean.getContent()).append(",");
            }
        }
        if (string.length() > 0) {
            string = new StringBuilder(string.substring(0, string.length() - 1));
        }
        return string.toString();
    }
}
